/**
 * fileName:  FruitEfficacyRelationReader.java
 * author:  lr
 * Company:  Cloudland Studio
 * Createdate:  2014-6-12 上午08:56:37
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-12          lr            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.read;


import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.store.DatabaseReader;
import org.cloudland.commercial.masterdata.store.entity.FruitEfficacyEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.EfficacyRelationEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.EfficacyRelationMapper;
import org.springframework.stereotype.Service;

 /**
 * <pre> 
 * 水果功效关系读取操作领域
 * 使用 java.lang.Object#toString(), 或者 {@link java.lang.Character Character} 等标签
 * </pre>
 * @ClassName  FruitEfficacyRelationReader
 * @author  lr
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
@Service
public class FruitEfficacyRelationReader implements DatabaseReader<FruitEfficacyEntity> {
	@Resource(name = "efficacyRelationMapper")
	private EfficacyRelationMapper efficacyRelationMapper;
	
	/**
	 * 
	 * <pre>
	 * 通过水果关系唯一主键ID查询水果关系
	 * </pre>
	 *
	 * @param fruitEfficacyId
	 * @return
	 */
	public FruitEfficacyEntity findFruitEfficacyById(String fruitEfficacyId) {
		FruitEfficacyEntity entity = null;
		EfficacyRelationEntity entityDao = efficacyRelationMapper.queryEfficacy(fruitEfficacyId);
		if (null != entityDao) {
			entity = new FruitEfficacyEntity(entityDao.getFruitId(), entityDao.getPartId(), entityDao.getEfficacyId(), entityDao.getEffcacyWeight(), entityDao.getSort());
		}
		return entity;
	}
	
	/**
	 * <pre>
	 * 根据水果编号获取所有结构的功效信息
	 * </pre>
	 *
	 * @param fruitId
	 * @return   
	 */
	public List<FruitEfficacyEntity> findEfficacyRelationByFruitId(String fruitId) {
		
		List<EfficacyRelationEntity> efficacyArray = efficacyRelationMapper.findEfficacyRelationByFruitId(fruitId);
		if (null == efficacyArray || efficacyArray.size() <= 0) {
			return new ArrayList<FruitEfficacyEntity>(0);
		}
		
		List<FruitEfficacyEntity> result = new ArrayList<FruitEfficacyEntity>(efficacyArray.size());
		FruitEfficacyEntity efficacy = null;
		for (EfficacyRelationEntity eff : efficacyArray) {
			efficacy = new FruitEfficacyEntity(eff.getFruitId(), eff.getPartId(), eff.getEfficacyId(), eff.getEffcacyWeight(), eff.getSort());
			result.add(efficacy);
		}
		
		return result;
	}
	
	
}
